@ read.S: read sycall wrapper
@
@ Authors: Nora Tarano  ntarano@andrew.cmu.edu
@          Yuan Meng    yuanm@andrew.cmu.edu
@          Yipeng Yun   yipengy@andrew.cmu.edu
@ Date:    Sat Oct 15, 2011

#include <bits/swi.h>
#include <bits/fileno.h>
#include <bits/errno.h>

	.file	"read.S"
	.text

	.extern	errno

	.global	read
read:
	swi	READ_SWI	  @ system call to read
	movs	r6, r0		@ make copy of return value
	bmi	set_errno	  @ if ret < 0, set errno appropriately
	b	read_end

set_errno:
	rsb	r6, r6, #0
	ldr	r7, =errno
	str	r6, [r7]	@ errno = abs(ret)
	mov	r0, #-1		@ set r0 = -1 (error)

read_end:
	mov	pc, lr
